#pragma	once

#include <boost/noncopyable.hpp>
#include <assert.h>

#pragma	warning(disable: 4661)

namespace	Z	{

//------------------------------------------------------------------------------------------------------------------------
template<typename T>
class	Singleton
	:	private boost::noncopyable
{
protected:
	static	T*	msSingleton;
public:
	Singleton()	{
		assert(msSingleton == nullptr);
#if defined( _MSC_VER ) && _MSC_VER < 1200	 
		int offset	= (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
		msSingleton	= (T*)((int)this + offset);
#else
	    msSingleton	= static_cast<T*>(this);
#endif
	}
	~Singleton()	{
		assert(msSingleton != nullptr);
		msSingleton	= nullptr;
	}
	static	T&	getSingleton()	{
		assert(msSingleton != nullptr);
		return *msSingleton;
	}
	static	T*	getSingletonPtr()	{
		return msSingleton;
	}
};

}